package jvm.oom;



import java.util.ArrayList;
import java.util.List;


/*
* vm args: -Xms20m -Xmx20m -XX:+HeapDumpOutOfMemoryError
* */
public class HeapOOM {

    public static void main(String[] args) {
        List<OOMObject> list = new ArrayList<>();
        while (true){
            list.add(new OOMObject());
        }
    }

//    java.lang.OutOfMemoryError: Java heap space
//    Dumping heap to java_pid43495.hprof ...
//    Heap dump file created [27874060 bytes in 0.265 secs]
//    Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
//    at java.util.Arrays.copyOf(Arrays.java:3210)
//    at java.util.Arrays.copyOf(Arrays.java:3181)
//    at java.util.ArrayList.grow(ArrayList.java:261)
//    at java.util.ArrayList.ensureExplicitCapacity(ArrayList.java:235)
//    at java.util.ArrayList.ensureCapacityInternal(ArrayList.java:227)
//    at java.util.ArrayList.add(ArrayList.java:458)
//    at jvm.oom.HeapOOM.main(HeapOOM.java:17)


    static class OOMObject{

    }
}
